#include "mycanvas.h"
#include "qmessagebox.h"
#include "lagrange.h"
MyCanvas::MyCanvas(QWidget *parent) :
    QWidget(parent)
{
    this->x_cotainferior = 0.0;
    this->x_cotasuperior = 0.0;
    this->y_cotainferior = 0.0;
    this->y_cotasuperior = 0.0;
    this->error = 0;


}

void MyCanvas::paintEvent(QPaintEvent* pEvent)
{
        this->Limpiar();
        Lagrange l=Lagrange(this->error, this->x_cotainferior, this->x_cotasuperior, -1.2, 1.2);
        l.pintarFuncion(this,this->funcion);
}

void MyCanvas::Limpiar()
{
    QPainter painter(this);
    QSize size = this->size();
    painter.fillRect(0,0,size.width(), size.height(), Qt::black);
    painter.setPen(Qt::red);
    //painter.drawLine(0,0,size.width(), size.height());
    painter.drawLine(size.width()/2,0,size.width()/2, size.height());
    painter.drawLine(0,size.height()/2,size.width(), size.height()/2);
}


